package cn.tedu.hospital.doctor.service.imol;

import cn.tedu.hospital.doctor.mapper.DoctorMapper;
import cn.tedu.hospital.doctor.pojo.dto.DoctorDto;
import cn.tedu.hospital.doctor.pojo.entity.DoctorEntity;
import cn.tedu.hospital.doctor.pojo.vo.DoctorVo;
import cn.tedu.hospital.doctor.service.DoctorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Slf4j
@Service
public class DoctorImpl implements DoctorService {
    @Autowired
    DoctorMapper doctorMapper;

    @Override
    public List<DoctorVo> select(DoctorDto doctorDto) {
        log.debug("开始处理查询医师的业务，参数：{}",doctorDto);
        List<DoctorVo> list = doctorMapper.select(doctorDto);
        log.debug("查询医师成功，查询结果：{}",list);
        return list;
    }

    @Override
    public void delete(Long doctorId) {
        log.debug("开始处理删除医师的业务，参数：{}",doctorId);
        doctorMapper.delete(doctorId);
    }
    @Override
    public void save(DoctorDto doctorDto) {
        DoctorEntity doctorEntity = new DoctorEntity();
        BeanUtils.copyProperties(doctorDto,doctorEntity);
        if (doctorDto.getId()==null){
            log.debug("开始处理添加医师的业务，参数：{}",doctorDto);
            doctorEntity.setRegistrationdate(new Date());
            doctorMapper.insert(doctorEntity);
        }else{
            log.debug("开始处理修改医师的业务，参数：{}",doctorDto);
            doctorEntity.setUpdatetime(new Date());
            log.debug("修改医师成功，修改结果：{}",doctorEntity);
            doctorMapper.update(doctorEntity);
        }

    }

}
